// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'

//先引入路由模块
import VueRouter from 'vue-router'
//把resource模块配置到vue中
Vue.use(VueRouter)

//引入axios插件
import axios from 'axios'
//把组件设置进Vue的原型中
Vue.prototype.axios = axios;

// 引入vuex模块
import Vuex from 'vuex'
// 安装模板
Vue.use(Vuex)

var store =new Vuex.Store({
    state: {
        money: 0,
        product:[
            {title:"pingguo",qt:2,price:5},
            {title:"li",qt:3,price:6},
            {title:"xiangjiao",qt:2,price:7},
        ],
        totel:0
    },
    mutations:{
        ADD_PRICE (state, price) {
            state.money += price;
            state.totel++;
        },
        REDUCE_PRICE (state, price) {
           state.money -= price;
           state.totel--;
        }
    },
    actions: { // 异步操作共享数据的方法
        reduce_Price (context, price) { // context代表store
            setTimeout(function(){
                context.commit('REDUCE_PRICE', price)
            }, 1000)
        }
         // reducePrice (context, price) { // 第一个参数为context，里面包含commit、dispatch等方法，如果commit使用很多，可以使用{ commit }
         //    console.log(context);
         //    setTimeout(function () {
         //        context.commit('REDUCE_PRICE', price)
         //    }, 1000);
        // }
    }
})


//引入四个路由组件
import Home from './pages/home'
import Cart from './pages/cart'
import Market from './pages/market'
import Mine from './pages/mine'

//详情页二级路由
import Xiang from './pages/xiang'
import Canshu from './pages/canshu'

// import Search from './pages/home/search'

import $ from 'jquery'
import '../static/reset.css'
import '../static/jquery-1.8.1.min.js'

//引入详情路由
import Detail from './pages/detail'
import Detail1 from './pages/detail1'
import Detail2 from './pages/detail2'
// 

// 引入swiper
import VueAwesomeSwiper from 'vue-awesome-swiper'
Vue.use(VueAwesomeSwiper)


//一级路由路径
let routes = [
  {path:'/detail2',component:Detail2,children:[{path:'',component:Xiang},                                        
                                           {path:'canshu',component:Canshu}, 
                                           {path:'xiang',component:Xiang}
                                                ]},
  {path:'/detail1',component:Detail1,children:[{path:'',component:Xiang},                                        
                                           {path:'canshu',component:Canshu}, 
                                           {path:'xiang',component:Xiang}
                                                ]},
  {path:'/detail/:id',component:Detail,children:[{path:'',component:Xiang},                                        
                                           {path:'canshu',component:Canshu}, 
                                           {path:'xiang',component:Xiang}
                                                ]},
  {path:'',component:Home},
  {path:'/home',component:Home},
  {path:'/cart',component:Cart},
  {path:'/market',component:Market},
  {path:'/mine',component:Mine}
  // {path:'/search',component}

]

//创建一个路由实例
let router = new VueRouter({
	  routes:routes
})

 
/* eslint-disable no-new */
new Vue({
  el: '#app',
  template: '<App/>',
  components: { App },
  router,
  store
})




